import { ipcMain, BrowserWindow } from 'electron'
import type { IpcMainEvent } from 'electron'

// 获取触发事件的窗口对象
const getWin = (event: IpcMainEvent) => {
  return BrowserWindow.fromWebContents(event.sender)!
}

ipcMain.on(
  'setWindowSize',
  (
    event: IpcMainEvent,
    opt: { aspectRatio: number; width?: number; height?: number }
  ) => {
    const win = getWin(event)

    // 控制窗口缩放比例
    win.setAspectRatio(opt.aspectRatio)
    // 控制窗口宽高
    win.setBounds({ width: opt.width, height: opt.height })
  }
)
